

    const Koa = require('koa');
    const KoaRouter = require('koa-router');

    const app = new Koa();
    const router = new KoaRouter();

    app.use(router.routes());
    app.use(router.allowedMethods());

    app.listen('3000', (err) => {
        if(err) console.log("koa 服务器启动失败");
        else console.log("koa 服务器启动成功，地址为http://localhost:3000");
    });

    router.get('/', (ctx, next) => {
        ctx.body = "<h1>Hello Koa Server</h1>";
    });

    router.get('/login', (ctx, next) => {
        ctx.res.writeHead(200, {'content-type': 'text/html; charset="utf-8"'});
        ctx.res.write("我在这里登录<br>");
        ctx.res.write("用户名：<input type='text' name='username'>");
        ctx.res.end();
    });
